package com.example.computer_exam_training_sys.controller;
import com.example.computer_exam_training_sys.entity.KnowledgeContent;
import com.example.computer_exam_training_sys.service.KnowledgeContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/knowledge/contents")
public class KnowledgeContentController {

    @Autowired
    private KnowledgeContentService contentService;

    // 查询指定知识点的内容
    @GetMapping
    public ResponseEntity<List<KnowledgeContent>> getByPointId(@RequestParam("pointId") Integer pointId) {
        return ResponseEntity.ok(contentService.getContentsByPointId(pointId));
    }

    // 添加新内容
    @PostMapping
    public ResponseEntity<String> addContent(@RequestBody KnowledgeContent content) {
        contentService.addContent(content);
        return ResponseEntity.ok("添加成功");
    }

    // 修改内容
    @PutMapping
    public ResponseEntity<String> updateContent(@RequestBody KnowledgeContent content) {
        contentService.updateContent(content);
        return ResponseEntity.ok("修改成功");
    }

    // 删除内容
    @DeleteMapping("/{id}")
    public ResponseEntity<String> deleteContent(@PathVariable("id") Integer id) {
        contentService.deleteContent(id);
        return ResponseEntity.ok("删除成功");
    }
}
